package com.byxy.test;

import com.byxy.dao.AdminRuleDao;
import com.byxy.model.AdminRule;
import com.byxy.service.AdminRuleService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TreeRecursionTest3 {
    @Autowired
    private AdminRuleService adminRuleService;
    @Autowired
    private AdminRuleDao adminRuleDao;
    @Autowired
    private HibernateTemplate hibernateTemplate;

    @Test
    public void main() {
//        List<AdminRule> list = getAdminRuleOne(0);
//        System.out.println(list.size());
        AdminRule adminRule = adminRuleService.get(0);
        System.out.println(adminRule);
    }

    public List<AdminRule> getAdminRuleOne(Integer parentId) {
        String hql = "FROM AdminRule WHERE parent.id = ?";
        List<AdminRule> list = (List<AdminRule>) hibernateTemplate.find(hql, parentId);
//        if (list != null && list.size() > 0) {
//            for (int i = 0; i < list.size(); i++) {
//                System.out.println("zzzz");
//                getAdminRuleOne(list.get(i).getId());
//            }
//        }
        return list;
    }
}
